package com.woniuxy.microsysserver.controller;//package com.woniuxy.microsysserver.serurity.acl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.microsysserver.entity.acl.Permission;
import com.woniuxy.microsysserver.entity.acl.RolePermission;
import com.woniuxy.microsysserver.service.PermissionService;
import com.woniuxy.microsysserver.service.RolePermissionService;
import com.woniuxy.microsysserver.uitl.ResponseEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 菜单管理
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@RefreshScope
@ApiOperation("平台端权限")
@RestController
@RequestMapping("/admin/acl/permission")
public class PermissionController {

    @Autowired(required = false)
    private PermissionService permissionService;
    @Autowired(required = false)
    private RolePermissionService rolePermissionService;

    //获取全部菜单
    @ApiOperation(value = "查询所有菜单")
    @GetMapping
    public ResponseEntity indexAllPermission () {
        List<Permission> list = permissionService.queryAllMenu();
        return ResponseEntity.ok().data("children", list);
    }

//    @ApiOperation(value = "递归删除菜单")
//    @DeleteMapping("remove/{id}")
////    @ControllerLog(description = "删除权限",modular = "权限管理")
//    public ResponseEntity remove (@PathVariable String id) {
//        permissionService.removeChildById(id);
//        return ResponseEntity.ok();
//    }

//    @ApiOperation(value = "给角色分配权限")
//    @PostMapping("/doAssign")
////    @ControllerLog(description = "分配权限",modular = "权限管理")
//    public ResponseEntity doAssign (String roleId, String[] permissionId) {
//        //分配新权限前首先删除角色原先的权限
//        QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("role_id",roleId);
//        rolePermissionService.remove(queryWrapper);
//        permissionService.saveRolePermissionRealtionShipGuli(roleId, permissionId);
//
//        return ResponseEntity.ok();
//    }

    @ApiOperation(value = "根据角色获取菜单")
    @GetMapping("toAssign/{roleId}")
    public ResponseEntity toAssign (@PathVariable String roleId) {
        List<Permission> list = permissionService.selectAllMenu(roleId);
        return ResponseEntity.ok().data("children", list);
    }

//
//    @ApiOperation(value = "新增菜单")
//    @PostMapping("save")
////    @ControllerLog(description = "新增菜单",modular = "菜单管理")
//    public ResponseEntity save (@RequestBody Permission permission) {
//        permission.setHiddenState(1);
//        permissionService.save(permission);
//        return ResponseEntity.ok();
//    }
//
//    @ApiOperation(value = "修改菜单")
//    @PutMapping("update")
////    @ControllerLog(description = "修改菜单",modular = "菜单管理")
//    public ResponseEntity updateById (@RequestBody Permission permission) {
//        permissionService.updateById(permission);
//        return ResponseEntity.ok();
//    }

}

